// 实现通知退出机制
package main

import (
	"log"
	"math/rand"
)

func main() {
	done := make(chan struct{})
	ch := GenerateIntA(done)

	log.Println(<-ch)
	log.Println(<-ch)
	log.Println(<-ch)

	close(done)

	log.Println("已经通知关闭了")
	log.Println(<-ch)

}

func GenerateIntA(done chan struct{}) chan int {
	ch := make(chan int)

	go func(c1 chan int) {
	Lable:
		for {
			select {
			case c1 <- rand.Int():
			case <-done:
				log.Println("done:关闭了")
				break Lable
			}
		}

		close(ch)
	}(ch)

	return ch
}
